package com.online_exam.controller.student.Dashboard;

import com.online_exam.base.RestResponse;
import com.online_exam.base.UserType;
import com.online_exam.domain.User;
import com.online_exam.domain.enums.ExamPaperTypeEnum;
import com.online_exam.service.ExamService;
import com.online_exam.service.UserService;
import com.online_exam.util.JwtUtil;
import com.online_exam.viewmodel.student.dashboard.IndexVM;
import com.online_exam.viewmodel.student.dashboard.PaperFilter;
import com.online_exam.viewmodel.student.dashboard.PaperInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController("StudentDashboardController")
@RequestMapping(value = "/api/student/dashboard")
public class DashboardController {

    @Autowired
    UserService userService;
    @Autowired
    ExamService examService;

    @RequestMapping(value = "/index", method = RequestMethod.POST)
    public RestResponse<IndexVM> index(HttpServletRequest request) {
        IndexVM indexVM = new IndexVM();
        User user = userService.getCurrent(UserType.Student,request.getCookies());
        System.out.println(user);

        PaperFilter paperFilter = new PaperFilter();
        paperFilter.setGradeLevel(user.getUserLevel());
        paperFilter.setExamPaperType(ExamPaperTypeEnum.Fixed.getCode());
        List<PaperInfo> fixedPaperInfos = examService.indexPaper(paperFilter);
        indexVM.setFixedPaper(fixedPaperInfos);
        return RestResponse.ok(indexVM);
    }
}
